package com.zhxt.web.controller.zhxtapi;

import com.zhxt.common.core.controller.BaseController;
import com.zhxt.common.core.domain.AjaxResult;
import com.zhxt.common.core.page.TableDataInfo;
import com.zhxt.system.domain.ZhxtContent;
import com.zhxt.system.service.IZhxtContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 管理系统-党建工团信息维护
 */

@RestController
@RequestMapping("/zhxtapi/union")
public class UnionController extends BaseController {
    //内容处理
    @Autowired
    private IZhxtContentService iZhxtContentService;

    /**
     * 分页查询党建工团列表
     */
    @PostMapping("/getUnionList")
    public TableDataInfo getUniontList(ZhxtContent zhxtContent){
        startPage();
        zhxtContent.setNrtype("union");
        List<ZhxtContent> zhxtContentsList = iZhxtContentService.getContentList(zhxtContent);
        return getDataTable(zhxtContentsList);
    }

    /**
     * 新增党建工团接口
     */
    @PostMapping("addUnion")
    public AjaxResult addUnion(ZhxtContent zhxtContent){
        AjaxResult ajax=AjaxResult.success();
        zhxtContent.setNrtype("union");
        if(zhxtContent.getTitle().isEmpty()){
            return AjaxResult.error("标题不能为空");
        }else if(zhxtContent.getDesc().isEmpty()){
            return AjaxResult.error("内容不能为空");
        }else if(zhxtContent.getImgurl().isEmpty()){
            return AjaxResult.error("图片地址不能为空");
        }else if(zhxtContent.getIndate().toString().isEmpty()){
            return AjaxResult.error("日期不能为空");
        }
        int aNum=iZhxtContentService.addContent(zhxtContent);
        if(aNum > 0){
            ajax.put("dcode","00");
            ajax.put("dresult","新增成功");
        }else{
            ajax.put("dcode","99");
            ajax.put("dresult","新增失败");
        }
        return ajax;
    }

    /**
     * 修改党建工团接口
     */
    @PostMapping("updateUnion")
    public AjaxResult updateUnion(ZhxtContent zhxtContent){
        AjaxResult ajax=AjaxResult.success();
        zhxtContent.setNrtype("union");
        if(zhxtContent.getTitle().isEmpty()){
            return AjaxResult.error("标题不能为空");
        }else if(zhxtContent.getDesc().isEmpty()){
            return AjaxResult.error("内容不能为空");
        }else if(zhxtContent.getImgurl().isEmpty()){
            return AjaxResult.error("图片地址不能为空");
        }else if(zhxtContent.getIndate().toString().isEmpty()){
            return AjaxResult.error("日期不能为空");
        }
        int uNum=iZhxtContentService.updateContent(zhxtContent);
        if(uNum > 0){
            ajax.put("dcode","00");
            ajax.put("dresult","修改成功");
        }else{
            ajax.put("dcode","99");
            ajax.put("dresult","修改失败");
        }
        return ajax;
    }

    /**
     * 删除党建工团
     */
    @PostMapping("delUnion")
    public AjaxResult delUnion(ZhxtContent zhxtContent){
        AjaxResult ajax=AjaxResult.success();
        zhxtContent.setNrtype("union");
        int dNum=iZhxtContentService.delContent(zhxtContent);
        if(dNum > 0){
            ajax.put("dcode","00");
            ajax.put("dresult","删除成功");
        }else{
            ajax.put("dcode","99");
            ajax.put("dresult","删除失败");
        }
        return ajax;
    }
}
